
/****
 * Copyright (C) 2006 dNux Team
 *                                                            ****
 * This program is free software; you can redistribute it and/or *
 * modify under the terms of the GNU General Public License as   *
 * published by the Free Software Foundation;                    *
 * either version 2 of the License.                              *
 *                                                               *
 * This program is distributed in the hope that it will be       *
 * useful, but WITHOUT ANY WARRANTY; without even the implied    *
 * warranty of without even the implied waranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.          *
 * See the GNU General Public License for more details.          *
 *                                                               *
 * You should have received a copy of the                        *
 * GNU General Public License                                    *
 * along with this program; if not, write to the                 *
 * Free Software Foundation, Inc.,                               *
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
 *                                                               *
 ****                                                         ****/

#ifndef __LIBDWGET_H__
#define __LIBDWGET_H__

#define LIBDWGET "libdwget"

#include <sys/types.h>
#include <sys/stat.h>

#include <dcore.h>
#include <dhash.h>
#include <curl/curl.h>

typedef int (*d_wget_progress_t)(void *data,
                                 double dltotal,
				 double dlnow,
				 double ultotal,
				 double ulnow);

typedef struct _d_wget_result_s {
  d_bool_t  downloaded;
  d_bool_t  size;
  d_hash_t  *hash;
} d_wget_result_t;

typedef struct _d_wget_s {
  char    *user_agent;
  char    *url;
  char    *dest;
  d_map_t *hash;
  unsigned size;
  d_wget_result_t *result;
  d_wget_progress_t progress;
  void *progress_data;
} d_wget_t;

d_wget_t *d_wget_new();
void      d_wget_free(d_wget_t **wget);
void      d_wget_result_free(d_wget_result_t **result);

d_wget_result_t *d_wget_get_result(d_wget_t *wget);

void      d_wget_set_url(d_wget_t *wget, char *url);
void      d_wget_set_dest(d_wget_t *wget, char *dest);
void      d_wget_set_hash(d_wget_t *wget, char *type, char *hash);
void      d_wget_set_hash_list(d_wget_t *wget, d_map_t *list);

void      d_wget_set_size(d_wget_t *wget, unsigned ko);
void      d_wget_set_user_agent(d_wget_t *wget, char *user_agent);
void      d_wget_set_progress_callback(d_wget_t *wget, d_wget_progress_t func);
void      d_wget_set_progress_data(d_wget_t *wget, void *data);

d_bool_t  d_wget_check(d_wget_t *wget);
d_bool_t  d_wget_file_exist(d_wget_t *wget);
void      d_wget_download(d_wget_t *wget, d_error_t **error);

void      d_wget_perform(d_wget_t *wget, d_error_t **error);

void      d_wget_result_display(d_wget_t *wget);

#endif /* __LIBDWGET_H__ */
